/**
 * 
 */
package com.ms.service.module.fish.db;

import org.hibernate.Session;

import com.ms.game.common.GameType;
import com.xpec.c4.db.hibernate.manager.HibernateManager;

/**
 * @author TW15010
 *
 */
public class FishDAO {
//	/**
//	 * 讀取載入牌桌資料
//	 * 
//	 * @param tableId
//	 * @return
//	 */
//	public static BacrMachineDataModel loadMachineModel(String tableId) {
//		Session session = HibernateManager.getSession();
//		Query query = session.createQuery("FROM BacrMachineDataModel Where halltype=:HALLTYPE");
//		query.setParameter("HALLTYPE", tableId);
//		BacrMachineDataModel model = (BacrMachineDataModel) query.uniqueResult();
//		return model;
//	}
//
//	/**
//	 * 儲存牌桌資料
//	 * 
//	 * @param model
//	 */
//	public static void updateMachineModel(BacrMachineDataModel model) {
//		if (model == null) {
//			return;
//		}
//
//		Session s = HibernateManager.txBegin();
//		s.saveOrUpdate(model);
//		HibernateManager.txCommitFailRollbackClearSession();
//	}

	
	/**
	 * 新增玩家日志
	 */
	public static void insertUserLog(UsrGameLog gameLog){
		if(gameLog == null) return;
		FishPlayerLogModel newModel = gameLog.toLogModel();
		
		Session session = HibernateManager.txBegin();
		session.save(newModel);
		HibernateManager.txCommitFailRollbackClearSession();
	}
	
	/**
	 * 建立儲存玩家 log 到 redis 時用的 key
	 * 
	 * @param tableId
	 * @param roundNumber
	 * @param playerId
	 * @return
	 */
	public static String createPlayerLogKeyOnRedis(String tableId, String playerId) {
		if (tableId == null || playerId == null) {
			return "";
		}

		String key = GameType.FISH.name() + ":" + tableId + ":" + playerId;
		return key;
	}
}
